package cn.syx.comtroller;

import cn.syx.service.RagService;
import org.springframework.ai.document.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class RagController {

    @Autowired
    private RagService ragService;

    /**
     * 向量存储
     * @return
     */
    @GetMapping("/embeddingStore")
    public List<Document> embeddingStore(){
        //文件加载
        List<Document> documents = ragService.loadText();
        // 切分
        List<Document> documentList = ragService.syxTextSplitter(documents);
        //向量存储
        ragService.documentWriter(documentList);
        return documentList;
    }


    /**
     * 向量查找
     * @param message
     * @return
     */
    @GetMapping("/embeddingSearch")
    public List<Document> embeddingSearch(@RequestParam String message){

        List<Document> documents = ragService.search(message);
        return documents;
    }
}
